package com.jf.cloud.service.sysmanager.common.taglib;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.IOException;

/**
 * sk 分页标签
 * @author ouyang  
 * jspp@qq.com
 */
@SuppressWarnings("all")
public class PageTag_Top extends BodyTagSupport {

  //private static Log log=LogFactory.getLog(PageGotoTag.class);
/**
* 第一页按钮名称
*/
private static final String BUTTON_FIRST_PAGE = "pageGoto_FirstPage";

/**
* 上一页按钮名称
*/
private static final String BUTTON_PRIOR_PAGE = "pageGoto_PriorPage";

/**
* 下一页按钮名称
*/
private static final String BUTTON_NEXT_PAGE = "pageGoto_NextPage";

/**
* 最后页按钮名称
*/
private static final String BUTTON_LAST_PAGE = "pageGoto_LastPage";

/**
* 跳转输入框名称
*/
private static final String TEXT_GOTO_PAGE = "pageGoto_GotoPageInput";

/**
* 跳转按钮名称
*/
private static final String BUTTON_GOTO = "pageGoto_Goto";

/**
* 隐藏域记录个数名称
*/
private static final String HIDDEN_RECORD_COUNT = "page.totalRows";

/**
* 隐藏域页面个数名称
*/
private static final String HIDDEN_PAGE_COUNT = "page.maxPage";

/**
* 隐藏域当前页面名称
*/
private static final String HIDDEN_CURRENT_PAGE = "page.curPage";

/**
* 隐藏域跳转页面名称
*/
private static final String HIDDEN_GOTO_PAGE = "page.gotopage";

/**
* 隐藏域每页面显示记录数名称
*/
private static final String HIDDEN_ROWS_PER_PAGE = "page.pageSize";

/**
* 导航条对应的form名称
*/
private String formName = "";

/**
* 默认方法为begin
*/
private String methodName = "begin";
 

/**
* 每页的记录条数
*/
private String rowsPerPage = String.valueOf(Paging.PAGE_SIZE);

public String getRowsPerPage() {
    //log.info("rowsPerPage==========="+rowsPerPage) ;
return rowsPerPage;
}

public void setRowsPerPage(String rowsPerPage) {
this.rowsPerPage = rowsPerPage;
}

public String getFormName() {
return formName;
}

public void setFormName(String formName) {
this.formName = formName;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
if(methodName!=null && methodName.trim().length()!=0)
   this.methodName = methodName;
}


/**
* 执行tag-lib输出
* @throws JspException
* @return int
 * @throws IOException
*/
public int doEndTag() {
	try {
		pageContext.getOut().write(this.getHtmlString());
	} catch (Exception e) {
		e.printStackTrace();
	}
    return SKIP_BODY;
}

/**
* 根据参数设置html输出信息
* 包括JavaScript以及NavigateButtons
* 将page信息设置为隐藏域，根据指定form进行提交。
* @return String
*/
private String getHtmlString() {

StringBuffer str = new StringBuffer();


/////////////获取page信息/////////////
Paging pageInfo = (Paging)(((HttpServletRequest)pageContext.getRequest()).getAttribute("page"));
if(pageInfo==null)pageInfo = new Paging();
int [] cnt = {10,20,30,50}; 
str.append("<div class=\"page_top_\">"+ "\n");
if(cnt != null && cnt.length > 0) {
	str.append("<div style=\"width:25%;display:inline;float:left;text-align:left;padding:3px 0px;\">"+ "\n");
	for(int i=0;i<cnt.length;i++){
		if(pageInfo.getPageSize()==cnt[i]){
			str.append("<span title=\"显示"+cnt[i]+"条记录\" class=\"curr_page_size\">"+cnt[i]+"</span>");
		}else{
			str.append("<a title=\"显示"+cnt[i]+"条记录\" class=\"page_size\" href=\"javascript:void(0);\" onclick=\"gotoPage(document." + this.formName + ", '" + cnt[i] + "',true);return false;\" >"+cnt[i]+"</a>");
		}
	}
	str.append("</div>"+ "\n");
	str.append("<div id=\"tfooter\" style=\"width:75%;display:inline;text-align:right;padding:3px 0px;\"></div>\n");
}
/*	str.append("<div class=\"lr\">"+ "\n");
	str.append("<i class=\"page_footer_info\">"+pageInfo.getCurPage()+"/"+pageInfo.getMaxPage()+"</i>" + "\n");
	if(pageInfo.getCurPage()-1<=0){
		str.append("<span class=\"prev\" title=\"没有上一页\">&nbsp;<b></b></span>");
	}else{
		str.append("<a title=\"上一页\" onclick=\"gotoPage(document." + this.formName + ", '" + BUTTON_PRIOR_PAGE + "');return false;\" class=\"prev\" href=\"javascript:void(0);\">&nbsp;<b></b></a>");
	}
	if(pageInfo.getCurPage()+1<=pageInfo.getMaxPage()){
		str.append("<a onclick=\"gotoPage(document." + this.formName + ", '" + BUTTON_NEXT_PAGE + "');return false;\" href=\"javascript:void(0);\"  class=\"next\">下一页 <b></b></a>");
	}else{
		str.append("<span class=\"next\" title=\"没有下一页\" >下一页 <b></b></span>");
	}
	str.append("</div>" + "\n");*/
str.append("</div>" + "\n");
return str.toString();
}

}
